package org.peterf.foxish.buffer;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.peterf.foxish.opengl20.OpenGLUtil.BufferUsage;
import org.peterf.foxish.opengl20.OpenGLUtil.Type;

/**
 * This maintains a {@link ByteBuffer} storing unsigned bytes used as index
 * buffer. You can call {@link #upload()} so that a VBO is potentially used.
 * <p>
 * To make this buffer the current buffer that OpenGL uses, simply call
 * {@link #use()}.
 * <p>
 * Upon OpenGL context lost, call {@link #upload()} to reload them.
 * <p>
 * Once the buffer is no longer in use, call {@link #delete()} to delete it.
 * 
 * @author peter
 * 
 */
public class IndexBufferB extends IndexBuffer {

    /**
     * Create a buffer for index.
     * 
     * @param data
     *            The data to be stored. They are regarded as unsigned, and
     *            would not affect the contents inside this after the
     *            construction.
     * @param usage
     *            The hint for the usage.
     */
    public IndexBufferB(byte[] data, BufferUsage usage) {
        super(data.length, usage);
        super.data = ByteBuffer.allocateDirect(data.length)
                .order(ByteOrder.nativeOrder()).put(data);
        super.data.position(0);
    }

    /**
     * Returns {@link Type#UNSIGNED_BYTE}.
     */
    @Override
    public Type getType() {
        return Type.UNSIGNED_BYTE;
    }

}
